define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'point/configcontent/index'+location.search,
                    add_url: 'point/configcontent/add'+location.search,
                    edit_url: 'point/configcontent/edit',
                    del_url: 'point/configcontent/del',
                    multi_url: 'point/configcontent/multi',
                    table: 'region_config_content',
                }
            });
            
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        /*{field: 'tag_id', title: __('Tag_id'),operate: 'LIKE %...%'},*/
                        {field: 'tag.name', title: __('Tag_id'),operate: 'LIKE %...%'},
                        {field: 'res.name', title: __('Resource_id'),placeholder: __('模糊查询'),operate: 'LIKE %...%'},
                        {field: 'resourcestatus', title: __('Resourcestatus'),searchList:{"0":__('否'),"1":__('是')},align: 'center',formatter: Table.api.formatter.toggle},
                        {field: 'exp.name', title: __('Export_id'),placeholder: __('模糊查询'),operate: 'LIKE %...%'},
                        {field: 'exportstatus', title: __('Exportstatus'),searchList:{"1":__('正'),"0":__('负')},align: 'center',formatter: Table.api.formatter.status},
                        {field: 'sumexpstatus', title: __('Sumexpstatus'),searchList:{"0":__('否'),"1":__('是')},align: 'center',formatter: Table.api.formatter.toggle},
                        {field: 'band', title: __('Band'), operate:'BETWEEN'},
                        {field: 'bandmatchrate', title: __('Bandmatchrate'), operate:'BETWEEN'},
                        {field: 'bandmatchstatus', title: __('Bandmatchstatus'),searchList:{"0":__('否'),"1":__('是')},formatter: Table.api.formatter.toggle},
                        {   field: 'payment',
                            title: __('Payment'),
                            searchList:{"0":paymentList[0],"1":paymentList[1],"2":paymentList[2],"3":paymentList[3],"4":paymentList[4],"5":paymentList[5],"6":paymentList[6],"7":paymentList[7]},
                            //searchList:{"0":__('无'),"1":__('第四峰值'),"2":__('95峰值'),"3":__('月均日峰值'),"4":__('固定结算'),"5":__('周峰值均值'),"6":__('第七峰值'),"7":__('月均日峰(去三高三低)')},
                            formatter: Table.api.formatter.normal},
                        {field: 'begintime', title: __('Begintime'), operate:false},
                        {field: 'endtime', title: __('Endtime'), operate:false},
                        {field: 'collectstatus', title: __('Collectstatus'),searchList:{"0":__('否'),"1":__('是')},align: 'center',formatter: Table.api.formatter.toggle},
                        {field: 'displayassess', title: __('Displayassess'),searchList:{"0":__('否'),"1":__('是')},align: 'center',formatter: Table.api.formatter.toggle},
                        {field: 'assessband', title: __('assessband'), operate:'BETWEEN'},
                        {field: 'comment',title: __('备注'),placeholder: __('模糊查询'),operate: 'LIKE %...%',formatter:function(value,row,index){
                            //var valuerep=value.replace(/\s*/g,"");
                            if(value){
                                    return '<div style="min-width:50px;">' + value + '</div><input type="text" class="form-control text-center" data-field="' + this.field + '" style="width:100%;display:none;min-width:50px;" value="' + value + '">';
                                
                                 }else{
                                    return '<div style="min-width:50px;">' + '<span>&nbsp;</span>'+ '</div><input type="text" class="form-control text-center" data-field="' + this.field + '" style="width:100%;display:none;min-width:50px;" value="">';
                           
                                 }
                            }, events: {

                                'click div': function (e, value, row, index) {
                                    $(this).hide();
                                    $(this).next().show().focus();
                                },
                                'keyup input': function (e, value, row, index) {
                                    if (e.keyCode == 13 || e.keyCode == 10) {
                                        $(this).trigger("blur");
                                    }
                                },
                                'blur input': function (e, value, row, index) {
                                    
                                    var that = this;
                                    var values = $(this).val();
                                    var values1=$(this).prev().text();
                                    console.log(values);
                                    console.log(values1);
                                    if(values1.replace(/\s*/g,"")=="" && values.replace(/\s*/g,"") == ""){
                                        $(that).prev().html('<span>&nbsp;</span>').show();
                                        $(that).attr("value","");
                                        $(that).hide();
                                        $(that).prev().show();
                                        return false;
                                    }
                                    if (values1 != values) {
                                        var data = {};
                                        data["row[" + $(that).data("field") + "]"] = values;
                                        Fast.api.ajax({
                                            url:  "point/configcontent/editcontcomment?ids=" + row.id+"&comment="+values,
                                            data: data
                                        }, function (data, ret) {
                                            $(that).hide();
                                            if(values.replace(/\s*/g,"") == ""){
                                                $(that).prev().html('<span>&nbsp;</span>').show();
                                                $(that).attr("value","");
                                                $(this).val("");
                                            }else{
                                                $(that).prev().text(values).show();
                                                $(that).attr("value",values);
                                                $(this).val(values);
                                            }
                                            
                                        });
                                    } else {
                                        $(that).hide();
                                        $(that).prev().show();
                                    }
                                }
                        }},
                        
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});